package com.school.system;

public class Student {
    // 学生属性
    private String studentId;   // 学生编号
    private String studentName; // 学生姓名
    private String gender;      // 学生性别
    private Course selectedCourse; // 所选课程（关联Course类，null表示未选课）

    // 构造方法：初始化学生基本信息
    public Student(String studentId, String studentName, String gender) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.gender = gender;
    }

    // 1. 选课方法：判断是否已选课，未选则成功选课
    public void selectCourse(Course course) {
        if (this.selectedCourse != null) {
            System.out.println("学生[" + studentName + "]已选课程[" + selectedCourse.getCourseName() + "]，不可重复选课");
        } else {
            this.selectedCourse = course;
            System.out.println("学生[" + studentName + "]成功选修课程[" + course.getCourseName() + "]");
        }
    }

    // 2. 退课方法：判断是否有已选课程，有则退课
    public void dropCourse() {
        if (this.selectedCourse == null) {
            System.out.println("学生[" + studentName + "]未选任何课程，无需退课");
        } else {
            System.out.println("学生[" + studentName + "]成功退选课程[" + selectedCourse.getCourseName() + "]");
            this.selectedCourse = null; // 置空表示退课成功
        }
    }

    // 3. 打印课表方法：格式化输出学生选课信息
    public void printSchedule() {
        System.out.println("\n===== 学生[" + studentName + "]课表 =====");
        if (this.selectedCourse == null) {
            System.out.println("当前未选修任何课程");
        } else {
            Course course = this.selectedCourse;
            System.out.println("课程编号：" + course.getCourseId());
            System.out.println("课程名称：" + course.getCourseName());
            System.out.println("上课地点：" + course.getLocation());
            System.out.println("上课时间：" + course.getTime());
            System.out.println("课程学分：" + course.getCredit());
            System.out.println("授课教师：" + course.getTeacher().getTeacherName());
        }
        System.out.println("=============================\n");
    }

    // Getter方法：供外部获取私有属性
    public String getStudentId() { return studentId; }
    public String getStudentName() { return studentName; }
    public String getGender() { return gender; }
    public Course getSelectedCourse() { return selectedCourse; }
}